/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objetos;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Usuario
 */
public class Reloj{
    
 
        DateFormat df;
        Timer timer;
        
        public Reloj() {
           
            df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
            df.setCalendar(Calendar.getInstance());
            timer = new Timer();
            timer.schedule(new DoTick(), 0, 1000);    // do it every second
            
           }
        
        public void cancel(){
            
            timer.cancel();
        }
        
        public void setReloj(Calendar cal){
            
            df.setCalendar(cal);
        }
        
        class DoTick extends TimerTask {
            public boolean sigue = true;
        @Override
            public void run() {
                
                Calendar c = df.getCalendar();
                System.out.println(df.format(c.getTime()));
                
                c.add(Calendar.SECOND, 1);
                df.setCalendar(c);
                
            }
         
        }
       
        public DateFormat getTime(){
            return df;
        }
     
}



